package flc.ast.utils;

import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.SPUtils;
import com.google.gson.reflect.TypeToken;

import java.util.List;

import flc.ast.bean.MyProtectionBean;
import flc.ast.bean.MyRecordBean;


public class AppSpUtils {
    private static final String SP_NAME = "appCollSp";
    private static final SPUtils sSpUtils = SPUtils.getInstance(SP_NAME);

    public static void saveProtectionList(List<String> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_protection_list, json);
    }

    public static List<String> getProtectionList() {
        String json = sSpUtils.getString(Key.key_protection_list);
        return GsonUtils.fromJson(json, new TypeToken<List<String>>() {
        }.getType());
    }

    public static void saveProtectionRecordList(List<MyProtectionBean> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_protection_record_list, json);
    }

    public static List<MyProtectionBean> getProtectionRecordList() {
        String json = sSpUtils.getString(Key.key_protection_record_list);
        return GsonUtils.fromJson(json, new TypeToken<List<MyProtectionBean>>() {
        }.getType());
    }

    public static void saveRecordList(List<MyRecordBean> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_record_list, json);
    }

    public static List<MyRecordBean> getRecordList() {
        String json = sSpUtils.getString(Key.key_record_list);
        return GsonUtils.fromJson(json, new TypeToken<List<MyRecordBean>>() {
        }.getType());
    }

    interface Key {
        String key_protection_list = "key_protection_list";
        String key_protection_record_list = "key_protection_record_list";
        String key_record_list = "key_record_list";
    }
}